<%
    String hostname = request.getServerName();
    int port = request.getServerPort();
    StringBuffer hostPath = new StringBuffer();
    
    hostPath.append(request.getScheme())
            .append("://")
            .append(hostname);
    
    // add port
    if (port != 80) {
        hostPath.append(":")
                .append(port);
    }
    
    // Add context path
    if (!request.getContextPath().isEmpty()) {
        hostPath.append(request.getContextPath());
    }
%>